//
//  UIBarButtonItem+Extension.swift
//  微博
//
//  Created by Mstarc on 2016/11/28.
//  Copyright © 2016年 Mstarc. All rights reserved.
//

import UIKit

//分类
extension UIBarButtonItem{
    
    //便利构造函数
    /// 创建UIBarButtonItem
    ///
    /// - parameter title:    title
    /// - parameter fontSize: fontSize 默认16号
    /// - parameter target:   target
    /// - parameter action:   action
    /// - parameter isBackBtn:   是否是返回按钮如果是 加箭头
    /// - returns: UIBarButtonItem
    convenience init(title:String,fontSize:CGFloat = 16,target:AnyObject?,action:Selector ,isBackBtn:Bool = false) {
        let btn:UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        if isBackBtn {
            let  imagename = "navigationbar_back_withtext"
            
            btn.setImage(UIImage(named:imagename), for: .normal)
            btn.setImage(UIImage(named:imagename + "_highlighted"), for: .highlighted)
            btn.sizeToFit()
        }
        
        
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        
        //self.init 实例化UIBarButtonItem
        self.init(customView:btn)
    }
}
